package com.kong.jobs;

import com.kong.constant.RedisConstant;
import com.kong.utils.QiNiuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author yang2013
 * @data 2020/10/12 16:53
 */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        System.out.println("=====quartz start====="+"sidffSize=="+sdiff.size());
        if (sdiff!=null && sdiff.size()>0) {
            for (String name : sdiff) {
                QiNiuUtils.removeFiles(name);
                System.out.println("删除垃圾图片成功");
                //删除时必须加上集合名称
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,name);
            }
        }
    }
}
